import CryptoJS from 'crypto-js'

const secretKey = import.meta.env.VITE_APP_SIGN // 密钥

// 请求头部
export const headerSign = 'requestSign'

export const aesEncrypt = (source: string) => {
  let key = CryptoJS.enc.Utf8.parse(secretKey) //32位
  let iv = CryptoJS.enc.Utf8.parse('1234567890000000') //16位
  let src = CryptoJS.enc.Utf8.parse(source)
  let encrypted = CryptoJS.AES.encrypt(src, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return encrypted.ciphertext.toString()
}

export const getCryptoString = () => {
  let timeStr = new Date().getTime() + '_' + Math.floor(Math.random() * 10000) + 1
  return aesEncrypt(timeStr)
}
